package com.wakala.employment.http.bean;

import android.os.Parcel;
import android.os.Parcelable;

import androidx.annotation.NonNull;

import java.io.Serializable;
import java.util.List;

/**
 * 条件过滤对象，构造多级检索条件
 */
public class FilterConditionVo implements Serializable, Parcelable {

    private static final long serialVersionUID=1L;


    private Integer id;


    private Integer pid;


    private String path;

    private Boolean hasChildren;

    /**
     * 条件ID
     */
    private Integer conditionId;
    /**
     * 条件名称
     */
    private String conditionName;

    /**
     * 条件属性
     */
    private Integer conditionAttrId;
    /**
     * 条件属性值
     */
    private String  conditionAttrValue;


    private String name;


    /**
     * 操作模式 0=单选-非必须 1=单选-必选 2-多选
     */
    private Integer mode;


    private Boolean status;

    private Integer sort;

    private List<FilterConditionVo> children;

    protected FilterConditionVo(Parcel in) {
        if (in.readByte() == 0) {
            id = null;
        } else {
            id = in.readInt();
        }
        if (in.readByte() == 0) {
            pid = null;
        } else {
            pid = in.readInt();
        }
        path = in.readString();
        byte tmpHasChildren = in.readByte();
        hasChildren = tmpHasChildren == 0 ? null : tmpHasChildren == 1;
        if (in.readByte() == 0) {
            conditionId = null;
        } else {
            conditionId = in.readInt();
        }
        conditionName = in.readString();
        if (in.readByte() == 0) {
            conditionAttrId = null;
        } else {
            conditionAttrId = in.readInt();
        }
        conditionAttrValue = in.readString();
        name = in.readString();
        if (in.readByte() == 0) {
            mode = null;
        } else {
            mode = in.readInt();
        }
        byte tmpStatus = in.readByte();
        status = tmpStatus == 0 ? null : tmpStatus == 1;
        if (in.readByte() == 0) {
            sort = null;
        } else {
            sort = in.readInt();
        }
        children = in.createTypedArrayList(FilterConditionVo.CREATOR);
    }

    @Override
    public void writeToParcel(Parcel dest, int flags) {
        if (id == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(id);
        }
        if (pid == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(pid);
        }
        dest.writeString(path);
        dest.writeByte((byte) (hasChildren == null ? 0 : hasChildren ? 1 : 2));
        if (conditionId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(conditionId);
        }
        dest.writeString(conditionName);
        if (conditionAttrId == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(conditionAttrId);
        }
        dest.writeString(conditionAttrValue);
        dest.writeString(name);
        if (mode == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(mode);
        }
        dest.writeByte((byte) (status == null ? 0 : status ? 1 : 2));
        if (sort == null) {
            dest.writeByte((byte) 0);
        } else {
            dest.writeByte((byte) 1);
            dest.writeInt(sort);
        }
        dest.writeTypedList(children);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    public static final Creator<FilterConditionVo> CREATOR = new Creator<FilterConditionVo>() {
        @Override
        public FilterConditionVo createFromParcel(Parcel in) {
            return new FilterConditionVo(in);
        }

        @Override
        public FilterConditionVo[] newArray(int size) {
            return new FilterConditionVo[size];
        }
    };

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Integer getPid() {
        return pid;
    }

    public void setPid(Integer pid) {
        this.pid = pid;
    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        this.path = path;
    }

    public Boolean getHasChildren() {
        return hasChildren;
    }

    public void setHasChildren(Boolean hasChildren) {
        this.hasChildren = hasChildren;
    }

    public Integer getConditionId() {
        return conditionId;
    }

    public void setConditionId(Integer conditionId) {
        this.conditionId = conditionId;
    }

    public String getConditionName() {
        return conditionName;
    }

    public void setConditionName(String conditionName) {
        this.conditionName = conditionName;
    }

    public Integer getConditionAttrId() {
        return conditionAttrId;
    }

    public void setConditionAttrId(Integer conditionAttrId) {
        this.conditionAttrId = conditionAttrId;
    }

    public String getConditionAttrValue() {
        return conditionAttrValue;
    }

    public void setConditionAttrValue(String conditionAttrValue) {
        this.conditionAttrValue = conditionAttrValue;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getMode() {
        return mode;
    }

    public void setMode(Integer mode) {
        this.mode = mode;
    }

    public Boolean getStatus() {
        return status;
    }

    public void setStatus(Boolean status) {
        this.status = status;
    }

    public Integer getSort() {
        return sort;
    }

    public void setSort(Integer sort) {
        this.sort = sort;
    }

    public List<FilterConditionVo> getChildren() {
        return children;
    }

    public void setChildren(List<FilterConditionVo> children) {
        this.children = children;
    }

    @NonNull
    @Override
    public String toString() {
        return name;
    }

}
